# encoding:utf-8

import requests
import base64
import json
import sys


QCodeee = 'qrcode.jpg'
filename = 'info.txt'


'''
二维码识别
'''

token = '24.691577679e18966cf6f0271740622ea1.2592000.1602319820.282335-22612358'

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/qrcode"
# 二进制方式打开图片文件
f = open(QCodeee, 'rb')
img = base64.b64encode(f.read())
f.close()
params = {"image":img}
access_token = '24.691577679e18966cf6f0271740622ea1.2592000.1602319820.282335-22612358'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())
    data1 = (response.json());
    data2 = data1['codes_result'][0]['text']
    str1 = "".join(data2)
    '''
    print(data2)
    print(type(data2))
    print(type(str1))
    '''
    f = open(filename, 'w')
    f.write(str1)
    f.close()




